home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18221 < prev    next >
Encoding:
Text File  |  1996-08-05  |  817 b   |  34 lines

  1. Path: news.cs.indiana.edu!djacobso@cs.indiana.edu
  2. From: "dan j" <djacobso@cs.indiana.edu>
  3. Newsgroups: comp.lang.c++
  4. Subject: Default values
  5. Date: Fri, 19 Apr 1996 08:50:13 -0500 (EST)
  6. Organization: Computer Science, Indiana University
  7. Message-ID: <26418@829921816>
  8. NNTP-Posting-Host: news.cs.indiana.edu
  9.  
  10. Is it somehow possible to use a class member variable as a default
  11. value to a member function?  When, if ever, can variables serve as
  12. default values?  For instance,
  13.  
  14. class tree {
  15.   tree_node * root;
  16.  
  17. public:
  18.   ...
  19.   foo(tree_node * ptr = root) { (recursive); }
  20.   ...
  21. };    
  22.  
  23. g++ (SunOS) says 'root' is not defined in this scope. 
  24.  
  25. A special function foo2() called with 'root' serves the purpose:
  26.  
  27.   foo(tree_node * ptr) { (recursive); }
  28.   foo2(void) { foo(root); }
  29.  
  30. But what is a better way to handle this?
  31.  
  32.  
  33. dan j
  34.